package cn.com.zero.front.auth.controller;

import cn.com.zero.api.auth.vo.LockedUserVO;
import cn.com.zero.db.vo.PageParamsVO;
import cn.com.zero.db.vo.PageVO;
import cn.com.zero.front.auth.constant.FrontAuthConstants;
import cn.com.zero.front.auth.service.impl.FrontLockedUserService;
import cn.com.zero.web.util.PageRequestUtil;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.Date;

/**
 * @author xiongxj
 * @version 1.0.0
 * @Description
 * @createTime 2023/3/30 17:06
 */
@RestController
@Api(tags = "用户端锁定用户接口")
@RequestMapping("/front/lockedUser")
public class FrontLockedUserController {

    private FrontLockedUserService frontLockedUserService;

    @GetMapping("/list")
    public PageVO<LockedUserVO> list(String[] searchUserIds, String loginIp,
                                     Date lockedBeginTime, Date lockedEndTime) {
        PageParamsVO pageParamsVO = PageRequestUtil.getPageParams();
        return frontLockedUserService.getLockedUsers(FrontAuthConstants.FRONT_SIDE_NAME, pageParamsVO,
                null == searchUserIds ? null : Arrays.asList(searchUserIds), loginIp, lockedBeginTime, lockedEndTime);
    }

    @PostMapping("/unlock")
    public void unlockUser(String userId) {
        frontLockedUserService.unlockUser(FrontAuthConstants.FRONT_SIDE_NAME, userId);
    }

    @Autowired
    public void setFrontLockedUserService(FrontLockedUserService frontLockedUserService) {
        this.frontLockedUserService = frontLockedUserService;
    }
}
